import React from 'react';
import { Modal } from 'antd';
import { history } from 'umi'
import { useRequest, defaultFormatResult } from '@/hooks';
import { getInterviewerDetail } from '@/pages/Recruitment/service';

const useBeforeInterview = ({ arrangeId }) => {
    const { data: detail = {} } = useRequest(() => getInterviewerDetail({ arrangeId }), {
        ...defaultFormatResult
    });

    const { absentInterviewFlag, absentInterviewOperateEmployeeName } = detail;

    const showContent = React.useCallback(() => {
        Modal.warning({
            title: '提醒',
            content: `您已被${absentInterviewOperateEmployeeName}面试官设置为缺席，无法填写面试记录`,
            okText: '确定',
            onOk() {
                history.goBack();
            }
        });
    }, [absentInterviewOperateEmployeeName]);

    React.useEffect(() => {
        if (absentInterviewFlag) {
            showContent();
        }
    }, [showContent, absentInterviewFlag]);
};

export default useBeforeInterview;
